<?php
/**
 * Created by PhpStorm.
 * Admininfo: Administrator
 * Date: 2018/3/21
 * Time: 15:37
 */
namespace app\admin\model;
use think\Model;
class Goodsclassify extends Model{
    protected $autoWriteTimestamp = true;
    protected $resultSetType = 'goodsclassify';
    protected $createTime = 'create_time';
    /**
     * @return \think\model\relation\HasMany
     */
    public  function child(){
        return  $this->hasMany('Goodsclassify','father_id')->where(['status'=>1])->order('sort asc');
    }
    /**
     * @param array $list
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public  static function getchildlist($classifyid){
        $where['father_id']=0;
        if($classifyid){
          $where['father_id']=$classifyid;
        }
        $where['status']=1;
        return collection(self::with('child')->where($where)->field('id,classify_name')->order('sort asc')->select())->toArray();
    }

}